#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent)
{


    //videoWidget = new Phonon::VideoPlayer(Phonon::VideoCategory,this);

       vlcvideo = new QWidget(this);
       inst = libvlc_new(0, NULL);

    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setStyleSheet("background:transparent;");

     embeedW = new QX11EmbedWidget(this);
     embeedW->setAttribute(Qt::WA_TranslucentBackground);
     embeedW->setStyleSheet("background:transparent;");

    /*qmlViewer = new QDeclarativeView(embeedW);
    qmlViewer->setResizeMode(QDeclarativeView::SizeRootObjectToView);
    qmlViewer->setWindowFlags(Qt::FramelessWindowHint);
    qmlViewer->setSource(QUrl::fromLocalFile("/socMDC/KdeadMouse/apps/videoplayer/qml/progressBar.qml"));
    qmlViewer->setAttribute(Qt::WA_TranslucentBackground);
    qmlViewer->setStyleSheet("background:transparent;");

    //qmlViewer->setWindowModality(Qt::ApplicationModal);
    qmlViewer->setWindowOpacity(0);
    //videoWidget->show();

    //sizing
    //videoWidget->setGeometry(50,50,600,600);
    //vlcvideo->setGeometry(50,50,600,600);
    qmlViewer->setGeometry(0,0,600,600);*/
    this->setGeometry(50,50,600,600);


    //showing
    this->show();


    //lancerVid
    //videoWidget->play(QUrl(texts));
    this->playVlcVid();

    embeedIt();

}
void QWidget::resizeEvent(QResizeEvent * e){
    qDebug()<<"resize";
}

void MainWindow::embeedIt(){

   // embeedW->embedInto(25165827);



    QX11EmbedContainer * container = new QX11EmbedContainer(this);

    container->setAttribute(Qt::WA_TranslucentBackground);
    container->setStyleSheet("background:transparent;");


    container->setGeometry(0,0,600,600);
    container->show();
    container->embedClient(132120579);
     container->update();

}

void MainWindow::playVlcVid(){
    QString m_name = "/home/manu/movie.avi";
    m = libvlc_media_new_path (inst, m_name.toStdString().c_str());

    /* Create a media player playing environement */
    libvlc_media_player_t *  mp = libvlc_media_player_new_from_media (m);

    /* No need to keep the media now */
    libvlc_media_release (m);


    //Ievietojam vlc QWidget rāmi + ar pārbaudi kas tev par sistemu
#if defined(Q_WS_X11)
    libvlc_media_player_set_xwindow(mp, vlcvideo->winId());
#elif defined(Q_WS_MAC)
    libvlc_media_player_set_nsobject(mp, vlcvideo->winId());
#elif defined(Q_WS_WIN)
    libvlc_media_player_set_hwnd(mp, vlcvideo->winId());
#else
#error "unsupported platform"
#endif

    /* play the media_player */
    libvlc_media_player_play (mp);
}


MainWindow::~MainWindow()
{
    delete videoWidget;
    delete qmlViewer;
}



















/*void MainWindow::paintEvent(QPaintEvent * ev)
 {
    QPainter painter(this);
    painter.setPen(Qt::blue);
    painter.setFont(QFont("Arial", 30));
    painter.drawText(rect(), Qt::AlignCenter, "Qt");
}*/
